
#include "Picture.h"
#include "../debug_new.h"

CPicture::CPicture(void)
{
	m_bTransparent = TRUE;
	m_clrTransparent = RGB(0,0,0);
}

CPicture::CPicture(UINT nID):CControl(nID)
{
	m_bTransparent = TRUE;
	m_clrTransparent = RGB(0,0,0);
}

CPicture::CPicture(wstring strCaption,UINT nID)
:	CControl(strCaption,nID)
{
	m_bTransparent = TRUE;
	m_clrTransparent = RGB(0,0,0);
}

CPicture::CPicture(DWORD dwStyle, wstring strCaption,const CRect &rc, UINT nID)
:	CControl(dwStyle, strCaption,rc, nID)
{
	m_bTransparent = TRUE;
	m_clrTransparent = RGB(0,0,0);
}

CPicture::CPicture(DWORD dwStyle, wstring strCaption, int x, int y, int cx, int cy, UINT nID)
:	CControl(dwStyle, strCaption, x, y, cx, cy, nID)
{
	m_bTransparent = TRUE;
	m_clrTransparent = RGB(0,0,0);
}

CPicture::~CPicture(void)
{
}

void CPicture::Paint(CDC* pDC)
{
	if(m_rcControl.IsRectEmpty())
	{
		return ;
	}

	if(!IsVisible())
	{
		return;
	}

	if(m_bmpPic.m_hBitmap)
	{
		CSize sz;
		m_bmpPic.GetSize(sz);
		CDC dcTmp;
		dcTmp.CreateCompatibleDC(NULL);
		HBITMAP hOldBmp = dcTmp.SelectBitmap(m_bmpPic.m_hBitmap);

		if(m_bTransparent)
		{
			pDC->TransparentBltEx(m_rcControl.left,m_rcControl.top,m_rcControl.Width(),m_rcControl.Height(),
				dcTmp.m_hDC,0,0,sz.cx,sz.cy,m_clrTransparent);
		}
		else
		{
			pDC->StretchBlt(m_rcControl.left,m_rcControl.top,m_rcControl.Width(),m_rcControl.Height(),
				dcTmp.m_hDC,0,0,sz.cx,sz.cy,SRCCOPY);
		}
		dcTmp.SelectBitmap( hOldBmp );
		dcTmp.DeleteDC();
	}
}